<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<!-- 射线设备检测 -->
<div class="row clearfix">
	
	<!-- 查询框 -->
	<div class="col-md-12" style="height: 60px;">
		<div class="row">
			<div class="col-md-3 col-md-offset-6 column">
				<div class="input-group">
  					<span class="input-group-addon">委托单位:</span>
  					<input type="text" class="form-control" id="autocompleteIpt" placeholder="请输入委托单位">
				</div>
			</div>
			
			<div class="col-md-1">
				  <button class="btn btn-default" type="button"  onclick="rayEquipment.serachBtnHandler()">查询</button>
			</div>
		</div>
		
	</div>
	

	<!-- 数据框 -->
	<div class="col-md-12 column">
		<table class="table table-responsive table-hover table-striped table-bordered" id="tableData">
			<thead>
				<tr>
					<th>#</th>
					<th>序号</th>
					<th>委托单位</th>
					<th>产品设备编号</th>
					<th>产品设备名称</th>
					<th>材料牌号</th>
					<th>射线种类</th>
					<th>射线机型号</th>
					<th>胶片型号</th>
					<th>像质计号器</th>
					<th>检测标准</th>
					<th>检测比例</th>
					<th>合格级别</th>
					<th>报告编号</th>
				</tr>
			</thead>
			<tbody>
				<c:forEach items="${p.list}" varStatus="status" var="obj">
					<tr>
						<td> <input type="checkbox" value="${obj.id }" ></td>
						<td> 
							${status.count} 
						</td>
						<td>${obj.delegate}</td>
						<td>${obj.equipmentNo}</td>
						<td>${obj.equipmentName}</td>
						<td>${obj.materialNo}</td>
						<td>${obj.rayType}</td>
						<td>${obj.rayModel}</td>
						<td>${obj.filmType}</td>
						<td>${obj.IQI}</td>
						<td>${obj.testStandard}</td>
						<td>${obj.testRatio}</td>
						<td>
							<c:choose>
								<c:when test="${obj.qualified == 0 }">Ⅰ</c:when>
								<c:when test="${obj.qualified == 1 }">Ⅱ</c:when>
								<c:when test="${obj.qualified == 2 }">Ⅲ</c:when>
								<c:when test="${obj.qualified == 3 }">Ⅳ</c:when>
								<c:when test="${obj.qualified == 4 }">Ⅴ</c:when>
								<c:otherwise>""</c:otherwise>
							</c:choose>
						</td>
						<td>${obj.no}</td>
					</tr>
				</c:forEach>
			</tbody>
		</table>
	</div>


	<!-- 分页 -->
	<div class="col-md-4 col-md-offset-6" id="pagination">
		
	</div>

	<div class="col-md-2 column col-md-offset-5">
		<div class="btn-group">
			<button type="button" class="btn btn-default"  onclick="rayEquipment.addBtnHandler()" >添加</button>
			<button type="button" class="btn btn-default"  onclick="rayEquipment.updateBtnHandler()">修改</button>
			<button type="button" class="btn btn-default"  onclick="rayEquipment.delBtnHandler()" >删除</button>
		</div>
	</div>
</div>


<!--弹出框  -->
<div class="modal fade" id="dataOperateMoal">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">射线设备检测</h4>
      </div>
      
      <div class="modal-body">
   		<form class="form-horizontal" role="form" id="dataOperateForm">
			<input type="hidden" name="id">
			
   			<div class="form-group">
   				<label class="col-md-2 control-label">委托单位:</label>
			    <div class="col-md-4">
			    	  <input type="text" class="form-control" id="delegate" name="delegate" placeholder="请输入" />
			   	</div>
   				
			   	 <label class="col-md-2 control-label">报告编号:</label>
			   	 <div class="col-md-4">
			      	<input type="text" class="form-control" id="no" name="no" placeholder="请输入"  >
			   	 </div>
  			</div>
  			
  			<div class="form-group">
			    <label class="col-md-2 control-label">设备名称:</label>
			    <div class="col-md-4">
			      <input type="text" class="form-control" id="equipmentName" name="equipmentName" placeholder="请输入" >
			    </div>
			    
			    <label class="col-md-2 control-label">设备编号:</label>
			    <div class="col-md-4">
			      <input type="text" class="form-control" id="equipmentNo" name="equipmentNo" placeholder="请输入" >
			    </div>
  			</div>
  			
  			<div class="form-group">
			    <label class="col-md-2 control-label">材料编号:</label>
			    <div class="col-md-4">
			      <input type="text" class="form-control" id="materialNo" name="materialNo" placeholder="请输入" >
			    </div>
			    
			     <label class="col-md-2 control-label">透照方式:</label>
			    <div class="col-md-4">
			      <select type="text" class="form-control" id="transilluminator" name="transilluminator" placeholder="请输入" >
			      	
			      	<c:forEach items="${transilluminator}"  var="obj" >
			      		<option value="${obj.id}">${obj.content}</option>
			      	</c:forEach>
			      	
			      </select>
			    </div>
  			</div>
  			
  			<div class="form-group">
			    <label class="col-md-2 control-label">射线种类:</label>
			    <div class="col-md-4">
			      <select class="form-control" id="rayType" name="rayType" >
			      	
			      	<c:forEach items="${rayType}"  var="obj" >
			      		<option value="${obj.id}">${obj.content}</option>
			      	</c:forEach>
			      	
			      </select>
			    </div>
			    
			    <label class="col-md-3 control-label">射线机型号</label>
			    <div class="col-md-3">
			    	<select class="form-control" id="rayModel" name="rayModel" >
			    	
			    	<c:forEach items="${rayModel}"  var="obj" >
			      		<option value="${obj.id}">${obj.content}</option>
			      	</c:forEach>
			    	
			    	</select>
			    </div>
  			</div>
  			
  			<div class="form-group">
			    <label class="col-md-2 control-label">胶片型号:</label>
			    <div class="col-md-4">
			      <select class="form-control" id="filmType" name="filmType">
			      	
			      	<c:forEach items="${filmType}"  var="obj" >
			      		<option value="${obj.id}">${obj.content}</option>
			      	</c:forEach>
			      	
			      </select>
			    </div>
			    
			    <label class="col-md-3 control-label">像质计型号:</label>
			    <div class="col-md-3">
			    	<select class="form-control" id="iqi" name="iqi">
			    		
			    		<c:forEach items="${IQI}"  var="obj" >
			      			<option value="${obj.id}">${obj.content}</option>
			      		</c:forEach>
			    		
			    	</select>
			    </div>
  			</div>
  			
  			<div class="form-group">
			    <label class="col-md-2 control-label">检测标准:</label>
			    <div class="col-md-4">
			      <select class="form-control" id="testStandard" name="testStandard">
			      
			      		<c:forEach items="${testStandard}"  var="obj" >
			      			<option value="${obj.id}">${obj.content}</option>
			      		</c:forEach>
			      
			      </select>
			    </div>
			    
			    <label class="col-md-2 control-label">检测比例:</label>
			    <div class="col-md-4">
			    	<input type="text" class="form-control" id="testRatio" name="testRatio" placeholder="请输入" >
			    </div>
  			</div>
  			
  			<div class="form-group">
			    <label class="col-md-2 control-label">合格级别:</label>
			    <div class="col-md-4">
			      <select class="form-control" id="qualified" name="qualified">
			      </select>
			    </div>
  			</div>
  			
   		</form>
      </div>
      
      
      <div class="modal-footer">
        <button type="button" class="btn btn-default" onclick="rayEquipment.saveBtnHandler()">保存</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->


<script type="text/javascript" src="js/pagination.js"></script>
<script type="text/javascript">
	
	/** 避免外部引用  **/
	var rayEquipment = function(){
		var qualifiedObj = ['Ⅰ','Ⅱ','Ⅲ','Ⅳ','Ⅴ'];
		var tableSort = ["delegate","equipmentNo","equipmentName"
		                 ,"materialNo","rayType","rayModel"
		                 ,"filmType","iqi","testStandard"
		                 ,"testRatio","qualified","no"
                         ];
		
		for(var i=0;i<qualifiedObj.length;i++) {
			$("#qualified").append("<option value=\""+i+"\">"+qualifiedObj[i]+"</option>");
		}
		/** 初始化下拉搜索框  **/
		$("#autocompleteIpt").typeahead({
			source: function (query, process) {
		        var p = "name=delegate&content="+query;
		        $.post('base/queryJson', p, function (data) {
		        	if(data.result) {
		        		var d = [];
		        		for(var i = 0;i<data.data.length;i++) {
		        			d.push(data.data[i]["content"]);
		        		}
			            process(d);	
		        	}
		        });
		    }
			,minLength : 0
		});
		
		$("#delegate").typeahead({
			source: function (query, process) {
		        var p = "name=delegate&content="+query;
		        $.post('base/queryJson', p, function (data) {
		        	if(data.result) {
		        		var d = [];
		        		for(var i = 0;i<data.data.length;i++) {
		        			d.push(data.data[i]["content"]);
		        		}
			            process(d);	
		        	}
		        });
		    }
			,minLength : 0
		});
		
		/** 初始化分页 **/
		$("#pagination").pagination( {
			pageNo    : 1
			,showPageCount : 5
			,pageCount : (${p.totalRow} +  global.pageSize  - 1) / global.pageSize
			,buttonClickCallback :function(p){
				
			}
	    });
		/** 表格刷新 **/
		flushTable = function(pageNo , pageSize , delegate ){
			var d = "pageNo="+pageNo+"&pageSize="+pageSize+(delegate ? "&delegate="+delegate : "");
			showLoding();
			
			$.post("detection/rayEquipment/queryJson", d ,
				 function( data ){
					hideLoading();
					$("#tableData tbody").markTBody(tableSort
							,data.list
							,function( i , item , field ) {
								if(field == "qualified"){
									return "<td>"+qualifiedObj[item[field]]+"</td>";
								}	
							}
					);
				}
			);
		};
		
		return {
			/** 搜索按钮 **/
			serachBtnHandler : function() {
				var s = $("#autocompleteIpt").val();
				flushTable( 1 , global.pageSize , s );
			}
			,/** 添加按钮 **/
			addBtnHandler : function () {
				$("#dataOperateForm").cleanForm();
				$('#dataOperateMoal').modal({backdrop : 'static'});
			}
			, /** 修改按钮 **/
			updateBtnHandler : function () {
				$("#dataOperateForm").cleanForm();
				var selected = $("#tableData input[type='checkbox']:checked");
				if(selected.length > 1 || selected.length <= 0) {
					showInfoMsg('请选择一个要修改的数据',true);
					return;
				}
				
				var id = selected.val();
				$.ajax({
					url:'detection/rayEquipment/get/'+id ,
					type : 'post' ,
					contentType: 'application/json' ,
					success : function( data ){
						$('#dataOperateMoal').modal({backdrop : 'static'});
						if(data) $("#dataOperateForm").formData(data);
					}
				});
				
				
			}
			, /** 删除按钮 **/
			delBtnHandler : function () {
				
				var selected = $("#tableData input[type='checkbox']:checked");
				if(selected.length > 1 || selected.length <= 0) {
					showInfoMsg('请选择一个要删除的数据',true);
					return;
				}
				
				var id = selected.val();
				$.ajax({
					url:'detection/rayEquipment/del/'+id ,
					type : 'post' ,
					contentType: 'application/json' ,
					success : function( data ){
						if(data.result) flushTable( 1  , global.pageSize );
						else showWarningMsg(data.msg);
					}
				});
			}
			,
			/** 保存按钮 **/
			saveBtnHandler : function () {
				$("#dataOperateForm").validation();
				if ($("#dataOperateForm").valid() == false) return;
				
				var data = $("#dataOperateForm").serializeJson();
				$.ajax({
					url:'detection/rayEquipment/save' ,
					type : 'post' ,
					contentType: 'application/json;charset=utf-8' ,
					data : JSON.stringify(data) ,
					success : function( data ){
						if(data.result) flushTable( 1  , global.pageSize );
						else showWarningMsg(data.msg);
					}
				});

				$('#dataOperateMoal').modal('hide');
			}
		};
	}();
	
</script>


